/*****************************************************************************
 * encoder.h
 *
 * Copyright (C) 2020 Jeasonvor 1101627719@qq.com
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 ****************************************************************************/
#ifndef __ENCODER_H__
#define __ENCODER_H__

/*****************************************************************************
 * Included Files
 ****************************************************************************/

/*****************************************************************************
 * Pre-processor Definitions
 ****************************************************************************/

/*****************************************************************************
 * Public Types
 ****************************************************************************/
typedef struct {
    unsigned int pin_a0;
    unsigned int pin_a1;
    unsigned int pin_a2;
} dev_encoder_pin_t;

/*****************************************************************************
 * Public Data
 ****************************************************************************/

/****************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
/*****************************************************************************
 * Public Function Prototypes
 ****************************************************************************/

/**
 * @brief:  编码器初始化
 *
 * @param[in]:  pin     -   编码器组引脚
 * @param[in]:  cnt     -   编码器数量
 *
 * @return:
 *
 * @note:   编码器的A0~A2引脚均为输入模式
 * **/
int dev_encoder_init(dev_encoder_pin_t pin[], int cnt);

/**
 * @brief:  读取编码器组的编码结果
 *
 * @param[in]:  grp     -   编码器组索引(以0为起点)
 *
 * @return:     大于等于0   -   正确读取到结果（A0~A2的编码值）
 *              小于0       -   读取失败
 *
 * @note:   [bit2~bit0] : A2 ~ A0
 * **/
int dev_encoder_read_grp(int grp);

/**
 * @brief:  读取编码器引脚状态
 *
 * @param[in]:   grp    -   编码器组ID
 * @param[in]:   idx    -   引脚ID(0~7对应Y0~Y7)
 *
 * @return:  电平值（0.低电平，1.高电平）
 */
bool dev_encode_read_idx(int grp, int idx);

/****************************************************************************/
#ifdef __cplusplus
}
#endif
/****************************************************************************/
#endif /* __ENCODER_H__ */
/****************************************************************************/
/*                                                                          */
/*  End of file.                                                            */
/*                                                                          */
/****************************************************************************/
